package com.ponhu.ea2.goodsCenter.provider.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;

/**
 * @author luyu
 * @create 2021-10-27 15:04
 * 创建商品推送胖总管时,用于计算胖总管的入库价,供货价,销售价
 */
@Slf4j
@Service
public class PhCalculatePriceService {

    private BigDecimal warehousingPrice = null;// 入库价
    private BigDecimal supplyPrice = null;// 供货价
    private BigDecimal salesPriceGuidance = null;// 建议销售价

    public Map<String,BigDecimal> countPrice(BigDecimal purchasePrice){
        Map<String,BigDecimal> map = new HashMap();
        // 组装数据
        putData(purchasePrice);
        map.put("WarehousingPrice",warehousingPrice);// 入库价
        map.put("SupplyPrice",supplyPrice);// 供货价
        map.put("SalesPriceGuidance",salesPriceGuidance);// 建议销售价
        return map;
    }

    private BigDecimal typeConversion(String s){
        return new BigDecimal(s);
    }

    private BigDecimal calculationRules(BigDecimal bigDecimal){
        BigDecimal multiply = bigDecimal.divide(new BigDecimal("10"))
                .setScale(0, RoundingMode.FLOOR).multiply(new BigDecimal("10"));
        return multiply;
    }

    private void putData(BigDecimal purchasePrice){
        // 采购价大于0且小于等于1000的
        if(purchasePrice.compareTo(BigDecimal.ZERO) == 1
                && purchasePrice.compareTo(typeConversion("1000")) < 1 ){
            warehousingPrice = calculationRules(purchasePrice.add(typeConversion("250")));
            supplyPrice = calculationRules(purchasePrice.add(typeConversion("450")));
            salesPriceGuidance = calculationRules(purchasePrice.add(typeConversion("700")));
        }
        // 采购价大于1000 小于等于2000
        if(purchasePrice.compareTo(typeConversion("1000")) == 1
                && purchasePrice.compareTo(typeConversion("2000")) < 1 ){
            warehousingPrice = calculationRules(purchasePrice.add(typeConversion("300")));
            supplyPrice = calculationRules(purchasePrice.add(typeConversion("700")));
            salesPriceGuidance = calculationRules(purchasePrice.add(typeConversion("1100")));
        }
        // 采购价大于2000 小于等于5000的
        if(purchasePrice.compareTo(typeConversion("2000")) == 1
                && purchasePrice.compareTo(typeConversion("5000")) < 1){
            warehousingPrice = calculationRules(purchasePrice.multiply(typeConversion("1.15")));
            supplyPrice = calculationRules(purchasePrice.multiply(typeConversion("1.3")));
            salesPriceGuidance = calculationRules(purchasePrice.multiply(typeConversion("1.5")));
        }
        // 采购价大于5000 小于等于10000
        if(purchasePrice.compareTo(typeConversion("5000")) == 1
                && purchasePrice.compareTo(typeConversion("10000")) < 1){
            warehousingPrice = calculationRules(purchasePrice.multiply(typeConversion("1.07")));
            supplyPrice = calculationRules(purchasePrice.multiply(typeConversion("1.2")));
            salesPriceGuidance = calculationRules(purchasePrice.multiply(typeConversion("1.35")));
        }
        // 采购价大于10000 小于等于20000
        if(purchasePrice.compareTo(typeConversion("10000")) == 1
                && purchasePrice.compareTo(typeConversion("20000")) < 1){
            warehousingPrice = calculationRules(purchasePrice.multiply(typeConversion("1.04")));
            supplyPrice = calculationRules(purchasePrice.multiply(typeConversion("1.08")));
            salesPriceGuidance = calculationRules(purchasePrice.multiply(typeConversion("1.18")));
        }
        // 采购价大于20000
        if(purchasePrice.compareTo(typeConversion("20000")) == 1){
            warehousingPrice = calculationRules(purchasePrice.multiply(typeConversion("1.03")));
            supplyPrice = calculationRules(purchasePrice.multiply(typeConversion("1.05")));
            salesPriceGuidance = calculationRules(purchasePrice.multiply(typeConversion("1.15")));
        }
    }

}
